/**
 * @description order
 * @author 赵子靖
 * @since 2017-12-17
 */
var Order = function() {
    var t = {
        path :'',
        init : function() {
            t.initView();
            t.initEvent();
        },
        initView : function() {
            
        },
        initEvent : function() {
            
        },
        //运输方式选择
        transportTypeChange:function(tabId){
            $("#transportType").find("span").each(function(){
                $(this).attr("class","btn btn-xs btn-white");
            });
            $("#"+tabId).attr("class","btn btn-xs btn-primary");
        },
        //订单提交（从购物车走）
        submitOrderFromCart:function(){
            var transportType = '';//配送方式
            $("#transportType").find("span").each(function(){
                if("btn btn-xs btn-primary"==$(this).attr("class")){
                    transportType = $(this).attr("transport");
                }
            });
            var orderRemark = $("#orderRemark").val();//备注
            var addressId = $("#orderAddressId").val();//收货地址
            if(Util.isEmpty(addressId)){
                layer.open({
                    content: '请输入收货地址信息'
                    ,skin: 'msg'
                    ,time: 2 //2秒后自动关闭
                });
                return;
            }
            layer.open({
                type: 2
                ,content: '处理中'
            });
            $.ajax({
                type:"POST",
                url:t.path+"/mobile/order/submitOrderFromCart.do",
                dataType:"json",
                data:{
                    transportType:transportType,
                    orderRemark:orderRemark,
                    addressId:addressId
                },
                async: false,
                cache:false,
                success:function(data){
                    layer.closeAll();
                    if(data.success){
                        //成功
                        layer.open({
                            content: data.msg
                            ,skin: 'msg'
                            ,time: 2 //2秒后自动关闭
                        });
                        //订单提交完成页面
                        window.location.href=t.path+"/mobile/order/forwardOrderSuccess.do?orderId="+data.order.oId;
                    }else{
                        //添加失败
                        layer.open({
                            title: [
                              '提交失败',
                              'background-color: #FF4351; color:#fff;'
                            ]
                            ,content: data.msg
                        });
                    }
                }
            });
        },
        //单个商品购买提交（不经过购物车）
        submitOrderOneShop:function(){
            var transportType = '';//配送方式
            $("#transportType").find("span").each(function(){
                if("btn btn-xs btn-primary"==$(this).attr("class")){
                    transportType = $(this).attr("transport");
                }
            });
            var orderRemark = $("#orderRemark").val();//备注
            var addressId = $("#orderAddressId").val();//收货地址
            var shopId = $("#shopId").val();
            var shopNum = $("#shopNum").val();
            if(Util.isEmpty(addressId)){
                layer.open({
                    content: '请输入收货地址信息'
                    ,skin: 'msg'
                    ,time: 2 //2秒后自动关闭
                });
                return;
            }
            layer.open({
                type: 2
                ,content: '处理中'
            });
            $.ajax({
                type:"POST",
                url:t.path+"/mobile/order/submitOrderOneShop.do",
                dataType:"json",
                data:{
                    transportType:transportType,
                    orderRemark:orderRemark,
                    addressId:addressId,
                    shopId:shopId,
                    shopNum:shopNum
                },
                async: false,
                cache:false,
                success:function(data){
                    layer.closeAll();
                    if(data.success){
                        //成功
                        layer.open({
                            content: data.msg
                            ,skin: 'msg'
                            ,time: 2 //2秒后自动关闭
                        });
                        //订单提交完成页面
                        window.location.href=t.path+"/mobile/order/forwardOrderSuccess.do?orderId="+data.order.oId;
                    }else{
                        //添加失败
                        layer.open({
                            title: [
                              '提交失败',
                              'background-color: #FF4351; color:#fff;'
                            ]
                            ,content: data.msg
                        });
                    }
                }
            });
        }
    }
    return t;
}();